﻿
using System;

abstract class Shape
{
    public abstract double Area { get; }
    public abstract bool IsValid { get; }
}

class Rectangle : Shape
{
    public double Length { get; }
    public double Width { get; }

    public override double Area => Length * Width;

    public override bool IsValid => Length > 0 && Width > 0;

    public Rectangle(double length, double width)
    {
        Length = length;
        Width = width;
    }
}

class Square : Rectangle
{
    public Square(double sideLength) : base(sideLength, sideLength)
    {
    }
}

class Triangle : Shape
{
    public double Side1 { get; }
    public double Side2 { get; }
    public double Side3 { get; }

    public override double Area
    {
        get
        {
            double p = (Side1 + Side2 + Side3) / 2;
            return Math.Sqrt(p * (p - Side1) * (p - Side2) * (p - Side3));
        }
    }

    public override bool IsValid
    {
        get
        {
            return Side1 > 0 && Side2 > 0 && Side3 > 0 && Side1 + Side2 > Side3 && Side2 + Side3 > Side1 && Side3 + Side1 > Side2;
        }
    }

    public Triangle(double side1, double side2, double side3)
    {
        Side1 = side1;
        Side2 = side2;
        Side3 = side3;
    }
}

class ShapeFactory
{
    public static Shape CreateShape(string shapeType, double[] parameters)
    {
        switch (shapeType)
        {
            case "rectangle":
                return new Rectangle(parameters[0], parameters[1]);
            case "square":
                return new Square(parameters[0]);
            case "triangle":
                return new Triangle(parameters[0], parameters[1], parameters[2]);
            default:
                throw new ArgumentException("Invalid shape type.");
        }
    }
}

class Program
{
    static void Main()
    {
        Shape[] shapes = new Shape[10];
        Random rand = new Random();
        
        for(int i = 0; i < 10; i++)
        {
            string shapeType = "";
            int type = rand.Next(3);
            switch (type)
            {
                case 0: shapeType = "rectangle";break;
                case 1: shapeType = "square"; break;
                case 2: shapeType = "triangle"; break;
            }
         

            double[] parameters = new double[3];
            for (int j = 0; j < parameters.Length; j++)
            {
                parameters[j] = rand.NextDouble() * 10 + 1;
            }

            shapes[i] = ShapeFactory.CreateShape(shapeType, parameters);
        }

        double totalArea = 0;
        for(int i = 0;i<shapes.Length;i++)
        {
            if (shapes[i].IsValid)
            {
                Console.WriteLine($"Area of the { i + 1} shape: {shapes[i].Area}");
                totalArea += shapes[i].Area;
            }
        }

        Console.WriteLine($"SumArea of the 10 Shapes：{totalArea}");
    }
}